<template>
  <div>
    <el-dialog
      :title="title"
      width="652px"
      :visible.sync="isShow"
      :before-close="handleClose"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form ref="form" label-width="130px" :model="form" :rules="rules">
        <el-form-item label="审批结果" prop="auditResult">
          <el-select placeholder="请选择审批结果" v-model="form.auditResult" :disabled="isWatch">
            <el-option v-for="item in AUDIT_LIST" :key="item.id" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="企业折扣" prop="discount" v-if="form.auditResult != 0">
          <el-input v-model="form.discount" :disabled="isWatch"></el-input>
          %
        </el-form-item>

        <el-form-item label="银行客户经理工号" prop="managerNo">
          <el-input v-model="form.managerNo" maxlength="10"></el-input>
        </el-form-item>

        <el-form-item label="审批意见" prop="platformAuditRemark">
          <el-input
            :disabled="isWatch"
            type="textarea"
            maxlength="200"
            show-word-limit
            v-model="form.platformAuditRemark"
            :rows="10"
          ></el-input>
        </el-form-item>
        <el-form-item v-if="!isWatch">
          <el-button type="primary" class="btn" @click="submit()">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { AUDIT_LIST } from '@/constants/auditModel.js'
export default {
  name: 'AuditPop',
  data() {
    return {
      title: '审核',
      isWatch: false,
      AUDIT_LIST,
      isShow: false,
      rules: {
        auditResult: [{ required: true, message: '请选择审核结果' }],
        platformAuditRemark: [{ required: true, message: '请填写审批意见' }],
        discount: [{ required: true, message: '请填写企业折扣' }],
      },
      form: {
        id: '',
        auditResult: null,
        platformAuditRemark: '',
        discount: '',
        managerNo: '',
      },
    }
  },
  methods: {
    show(item) {
      console.log('item=64=', item)
      if (item.isWatch) {
        this.title = '查看'
      }
      this.form.id = item.id
      this.form.platformAuditRemark = item.platformAuditRemark || ''
      this.form.auditResult = item.auditResult || null
      this.form.managerNo = item.managerNo || ''
      this.form.discount = item.appCode === 'WMR' ? 0 : item.discount

      this.isWatch = item.isWatch || false
      this.isShow = true
      // console.log("this.form==",this.form);
    },
    submit() {
      this.$refs['form'].validate(async valid => {
        if (!valid) return
        // await this.submitRequest()
        await this.$http.post(`/credit_applys/${this.form.id}/platform_audit`, this.form)
        this.resetData()
        this.$emit('closePop', true)
      })
    },
    handleClose() {
      console.log('1111111')
      this.resetData()
    },
    resetData() {
      this.form.id = ''
      this.form.auditResult = null
      this.form.platformAuditRemark = ''
      this.form.managerNo = ''
      this.form.submit = ''
      this.form.discount = ''
      this.title = '审核'
      this.isWatch = false
      this.$refs['form'].resetFields()
      this.isShow = false
    },
    // async submitRequest() {
    //   console.log('aa2222a',this.form)

    // },
  },
}
</script>

<style lang="scss" scoped>
.btn {
  width: 400px;
}
::v-deep {
  .el-input {
    width: 400px;
  }
  .el-input__inner {
    width: 400px;
  }
  .el-textarea {
    width: 400px;
  }
}
</style>
